layui.use(['table', 'jquery'], function (data) {
    var table = layui.table,
        $ = layui.jquery;


    var tableIns = table.render({
        elem: "#produceWarehouse",
        height: 'full-125',
        url: ctx + '/warehouse/selectProduceByParams',
        page: true,
        cellMinWidth: 80, // 单元格最小宽度
        toolbar: '#toolbarDemo',
        cols: [[// 表头
            {type: 'checkbox'},
            {type: "numbers"},
            {
                title: "项目编号", field: "projectNo", templet: function (data) {
                    return data.projectBean.projectNo
                }
            },
            {
                title: "产品名称", field: "productName", templet: function (data) {
                    return data.projectBean.basicQuotationBean.productName
                }
            },
            {
                title: "入库数量", field: "productCount", templet: function (data) {
                    return data.projectBean.basicQuotationBean.productCount
                }
            },
            {
                title: "出库数量", field: "outCount"
            },
            {
                title: "结余数量", field: "stockCount"
            },
            {
                title: "出库时间", field: "outDate"
            }
            ,
            {
                title: "出库申请人", field: "outerId", templet: function (data) {
                    if (data.empBean == null) {
                        return ""
                    } else {
                        return data.empBean.empName;
                    }
                }
            },
            {
                title: "状态", field: "outStatus", templet: function (data) {
                    if (data.outStatus == 0) {
                        return "暂未出库"
                    } else if (data.outStatus == 1) {
                        return "待审核"
                    }else if (data.outStatus == 2){
                        return  "已出库"
                    }
                }
            },
            {
                title: "操作", templet: "#tool"
            }

        ]]
    })

    table.on('tool(produceWareHouseFilter)', function (data) {
        if (data.event == "outProduce") {
            layer.confirm("确认审核成品出库嘛", {title: "成品出库"}, function (index) {
                layer.close(index);
                $.ajax({
                    type: "post",
                    data: {
                        id: data.data.id
                    },
                    url: ctx + "/warehouse/outProduce",
                    success: function (data) {
                        if (data.code == 200) {
                            layer.msg(data.msg)
                            tableIns.reload()
                        } else {
                            layer.msg(data.msg)
                        }
                    }, error: function (data) {
                        layer.msg(data)
                    }

                })
                return false;
            })
        }
    })


})


